package com.hqyj.shop.controller;

import com.hqyj.shop.dao.DetailDao;
import com.hqyj.shop.pojo.Detail;
import com.hqyj.shop.pojo.Order;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/manager")
public class DetailController {

    @Autowired
    private DetailDao detailDao;

    @RequestMapping("/getAll")
//    @ResponseBody
    public String getAllOrderByPage(ModelMap modelMap) {
        //调用服务层返回模型数据
        List<Order> pageData = detailDao.queryByOrderId();
        //给视图传递上下文参数
        modelMap.put("Detail", pageData);
        //请求转发到success.jsp
        return "detail";
    }


//    @RequestMapping("/updateOrder")
//    public String updateOrderByPage(Order order,ModelMap modelMap){
//        detailDao.updateOneDetail(order);
//        return "redirect:/manager/getAll";
//    }

    @RequestMapping("/updateOrder")
    public String updateOrderByPage(@Param("orderId") int orderId,@Param("status") String status){
        System.out.println(orderId+status);
        detailDao.updateOneDetail(orderId,status);
        return "redirect:/manager/getAll";
    }

}
